package com.guangfeng.yql.comm.netty.chatroom;

import com.guangfeng.yql.comm.netty.util.ChatRoomTextMessageSendUtil;
import com.guangfeng.yql.comm.netty.util.ChatRoomUtil;
import io.netty.channel.group.ChannelGroup;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Map;

@Slf4j
@Component
public class ChatRoomScheduling {

    @Scheduled(fixedDelay = 1000)
    public void sendTextMessage() {
        // 获取信息列表
        Map<Integer, ChannelGroup> map = ChatRoomUtil.getChatRoomChannelAll();
        // 将列表信息发送出去
        map.forEach((key, value) -> ChatRoomTextMessageSendUtil.sendListMessageCollection(ChatRoomMessageQueue.getAll(key.toString()), value));
    }


}
